package com.cmict.data.form.api.task;

import com.cmict.data.form.api.service.SysFormService;
import com.cmict.data.form.api.util.AssemblyTypeUtil;
import com.cmict.data.framework.common.pojo.CommonResult;
import com.cmict.data.form.api.task.dto.SysFromSeachDataVoDTO;
import com.cmict.data.form.api.convert.SysFormConvert;
import com.cmict.data.form.api.entity.vo.SysFromSeachDataVo;
import com.cmict.data.form.api.mapper.SysCurrencyMapper;
import com.cmict.data.form.api.service.SysCurrencyService;
import com.cmict.data.system.api.user.AdminUserApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.*;

import static com.cmict.data.framework.common.pojo.CommonResult.success;

/**
 * 表单数据 API 实现类
 *
 * @author awesome
 */
@RestController
public class CurrencyDataApiImpl implements CurrencyDataApi {
    private static final Logger logger = LoggerFactory.getLogger(CurrencyDataApiImpl.class);

    @Value("${spring.datasource.dynamic.datasource.slave.name}")
    private String tableSchema;

    @Value("${spring.datasource.dynamic.datasource.master.name}")
    private String tableMaster;

    @Resource
    private AdminUserApi adminUserApi;

    @Resource
    private SysCurrencyService sysCurrencyService;

    @Resource
    private SysCurrencyMapper sysCurrencyMapper;

    @Resource
    private SysFormService sysFormService;

    @Override
    public CommonResult<List<String>> getTableNameList(String sql) {
        return success(sysCurrencyService.getTableNameList(sql));
    }

    Integer PAGE_CURRENT = 0; // 分页默认页数
    Integer PAGE_SIZE = 10; // 分页默认数量

    @Override
    public CommonResult selectData(SysFromSeachDataVoDTO sysFromSeach) {
       SysFromSeachDataVo sysFromSeachData =  SysFormConvert.INSTANCE.convertSeach(sysFromSeach);
        return   sysCurrencyService.selectData(sysFromSeachData);
    }

    @Override
    public void deleteData(String sql) { sysCurrencyMapper.deleteData(sql);
    }

    @Override
    public List<Map<String,Object>> selectDataList(String sql)
    {
        return sysCurrencyMapper.selectData(sql);
    }

    @Override
    public CommonResult<List<Map<String, Object>>> selectDataByPortal(String tableName, List<Map<String, Object>> dataMapList) {
        List<Map<String, Object>> data = AssemblyTypeUtil.associatedDataMapping(tableName, dataMapList, "portal").getData();
        return success(data);
    }

    @Override
    public CommonResult<List<Map<String, Object>>> selectDataByChange(Long id, List<Map<String, Object>> dataMapList) {
        List<Map<String, Object>> data = AssemblyTypeUtil.associatedDataMapping(id, dataMapList, null).getData();
        return success(data);
    }
}
